package cn.gjxblog.modules.sys.controller;

import cn.gjxblog.common.model.HttpResult;
import cn.gjxblog.common.model.PageInfo;
import cn.gjxblog.modules.sys.entity.SysUserEntity;
import cn.gjxblog.modules.sys.model.vo.DeleteRequest;
import cn.gjxblog.modules.sys.model.vo.UserListRequest;
import cn.gjxblog.modules.sys.service.SysUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 系统用户
 *
 * @author guojiaxun
 * @date 2019-09-17 11:18:39
 */
@RestController
@RequestMapping("sys/sysuser")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;

    /**
     * 列表
     */
    @PostMapping("/list")
    @ApiOperation("获取列表")
    public HttpResult list(@RequestBody UserListRequest request){
        PageInfo<SysUserEntity> pageInfo = sysUserService.searchList(request);
        return HttpResult.ok(pageInfo);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{userId}")
    @ApiOperation("获取信息")
    public HttpResult info(@PathVariable("userId") Long userId){
		SysUserEntity sysUser = sysUserService.getById(userId);

        return HttpResult.ok();
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("保存信息")
    public HttpResult save(@RequestBody SysUserEntity sysUser){
		sysUserService.save(sysUser);

        return HttpResult.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation("修改成功")
    public HttpResult update(@RequestBody SysUserEntity sysUser){
		sysUserService.updateById(sysUser);

        return HttpResult.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation("删除成功")
    public HttpResult delete(@RequestBody DeleteRequest request){
		sysUserService.removeByIds(request.getIds());
        return HttpResult.ok();
    }

}
